package com.lw.server;

import java.util.*;

/**
 * 管理和客户端通信的线程
 */
public class ManageClientThread {

    /**
     * 线程池， Key:userId
     */
    private static HashMap<String,ServerConnectClientThread> threadHashMap = new HashMap<>();

    public static void addClientThread(String userId, ServerConnectClientThread thread){
        threadHashMap.put(userId,thread);
    }

    public static ServerConnectClientThread getClientThread(String userId){
        return threadHashMap.get(userId);
    }

    public static void removeClientThread(String userId){
        threadHashMap.remove(userId);
    }

    public static List<ServerConnectClientThread> getAllClientConnectServerThread(){
        return threadHashMap.values().stream().toList();
    }


    /**
     * 返回在线用户列表
     * @return
     */
    public static String getOnlineUser(){
        Iterator<String> iterator = threadHashMap.keySet().iterator();
        StringBuffer sb = new StringBuffer();
        while (iterator.hasNext()){
            sb.append(iterator.next()+" ");
        }
        return sb.toString();
    }

}
